<?php /**
 * Created by PhpStorm.
 * @User: 王崇全
 * @Date: 2019/1/18 15:24
 */


function dosql(string $sql){
    $dsn      = 'mysql:host=120.24.0.243;dbname=fhh';
    $user     = 'fhh';
    $password = 'NDNwF5YK3ee3m4YS';
    $status   = 1;

    //连接数据库
    $dbh = new PDO($dsn, $user, $password);

    //设置参数
    // $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);



    $stmt = $dbh->prepare($sql);

    $score = 61;
    $stmt->bindParam(':score', $score);

    //执行sql
    $stmt->execute();

    return $stmt->fetchAll(PDO::FETCH_ASSOC);
}


$sql="SELECT
	students.sex,
	avg( score.score ) 
FROM
	`score`
	LEFT JOIN students ON students.id = score.sudent_id 
WHERE
	score.course = '计算机操作系统' 
GROUP BY
	students.sex";

$res=dosql( $sql);

var_export($res);
